<?php


header('Content-Type: image/jpeg');

$user=$_GET['user'];

if( !preg_match("/^http:\/\//",$_GET['img'])){
   $url="http://".$_GET['img'];
}
else{
   $url=$_GET['img'];
}


//$url_ref="http://".$_GET['img_ref'];


preg_match("/([^\/]+)$/",$_GET['img'],$matched);

$full_name="./xys_image/".$matched[1];

if(file_exists($full_name) )
{
	$url=$full_name;
	$fh=fopen($url,"r");
	while(!feof($fh)) {
 	echo fgets($fh, 4096);
	}
	fclose($fh);
}
else
{
$fh=fopen($url,"r");
$output=NULL;
while(!feof($fh)) {
 		$line=fgets($fh, 4096);
		$output.=$line;
		echo $line;
}
fclose($fh);

$fh2=fopen($full_name,"w");
fwrite($fh2,$output);
fclose($fh2);

system("convert -resize 450x600 $full_name $full_name ");

}

?>
